import { Ref } from 'vue'
import { PolylineType, LinePathType, DrivingInfoType } from './type'
import markerIcon from '@/assets/image/icon/point.png'

export function Driving(
  currentMap: any,
  AMap: any,
  pathData: any,
  playOptional: any,
) {
  // const driving = new AMap.Driving({
  //   map: currentMap,
  //   panel: 'panel',
  // })
  // let index = 0
  // const timerId = setInterval(function () {
  //   if (index < data.length) {
  //     driving.search(
  //       data[index],
  //       data[index + 1],
  //       function (status: any, result: any) {
  //         if (status === 'complete') {
  //           // 路径规划成功，可以在result中获取到路径信息
  //           console.log(result, 778)
  //         } else {
  //           // 路径规划失败，可以根据status进行错误处理
  //           console.log(status, result, '路径规划失败')
  //         }
  //         console.log(result, 689989)
  //       },
  //     )
  //     index++
  //   } else {
  //     clearInterval(timerId)
  //     console.log('路径播放完成')
  //   }
  // }, 2000) // 每2秒显示一个路径段
  const { AMapUI } = window as any
  AMapUI.load(['ui/misc/PathSimplifier'], (PathSimplifier: any) => {
    if (!PathSimplifier.supportCanvas) {
      alert('当前环境不支持 Canvas！')
      return
    }
    const pathSimplifierIns = new PathSimplifier({
      zIndex: 100,
      map: currentMap, // 所属的地图实例
      getPath: function (pathData: any, pathIndex: any) {
        return pathData.path
      },
      getHoverTitle: function (pathData: any, pathIndex: any, pointIndex: any) {
        if (pointIndex >= 0) {
          return (
            pathData.name + '，点：' + pointIndex + '/' + pathData.path.length
          )
        }
        return pathData.name + '，点数量' + pathData.path.length
      },
      renderOptions: {
        renderAllPointsIfNumberBelow: 100, // 绘制路线节点，如不需要可设置为-1
      },
    })

    // 设置数据
    pathSimplifierIns.setData([
      {
        name: '路线0',
        path: pathData,
      },
    ])

    // 对第一条线路（即索引 0）创建一个巡航器
    const navg1 = pathSimplifierIns.createPathNavigator(0, {
      loop: false, // 循环播放
      speed: 10000, // 巡航速度，单位千米/小时
    })
    navg1.start()
  })
}
